<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击</button>
    <script>
        var that;
        var _that;
        class Star {
            constructor(uname, age) {
                that = this;
                this.uname = uname;
                this.age = age;
                this.btn = document.querySelector('button');
                this.btn.onclick = this.sing;
            }
            sing() {
                // console.log('hi');
                // console.log(uname);
                //这个sing里面的this指向btn，因为按钮调用了这个函数
                console.log(that.uname);
            }
            dance() {
                _that = this;
                console.log(this);
            }
        }
        var star = new Star('刘德华');
        star.sing();
        //1. 在ES6中类没有变量提升，所以必须先定义类，才能通过类实例化对象
        //2.类里面的共有属性和方法一定要加this使用
        //3.this的指向问题
        console.log(that === star);
        star.dance();
        console.log(_that === star);
    </script>
</body>

</html>